/*
Date:20210430 23:05PM
key:实现了一个动态扩容的栈。
    首先是count设定成-1，先count++,再放元素。因为pop的时候，如果count++在后，pop一次后去掉的是未放置的位置，那第一次pop就要pop两次才能弹出栈顶，不合适。

*/
class MinStack {
public:
    int Max_Size=4;
    int*stack=new int[Max_Size];
    int count;
    /** initialize your data structure here. */
    MinStack() 
    {
        count=-1;
    }
    
    void push(int val) 
    {

        count++;
        stack[count]=val;
        if(count+1==Max_Size)
        {
            Max_Size=Max_Size<<1;
            int*stack1=new int[Max_Size];
            for(int i=0;i<=count;i++)
            {
                stack1[i]=stack[i];
            }
            //delete stack;
            stack=stack1;
        }
    }
    
    void pop() 
    {
        count--;
        
    }
    
    int top() 
    {
        return stack[count];
    }
    
    int getMin() 
    {
        int min=INT_MAX;
        for(int i=0;i<=count;i++)
        {
            if(min>stack[i]){min=stack[i];}
        }
        return min;
    }
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */